package com.gok.kanmeituyun2.util.regex;

import java.util.regex.Pattern;

/**
 * @Company
 * @Classname
 * @Description TODO 正则表达式类来实现 登录信息检验
 * @Author wbs
 * Date 2021.6.18 10:41
 * Version 1.0
 */
public class RegexUtil {
    /**
     * 定义正则表达式
     */
    //电信手机号码正则
    private static final String TELECOMMUNI_REGEX = "^1[3578][01379]\\d{8}$";
    //联通手机号正则
    private static final String UNICOM_REGEX = "^1[34578][01256]\\d{8}$";
    //移动手机号正则
    private static final String MOBILE_REGEX = "^(134[012345678]\\d{7}|1[34578][012356789]\\d{8})$";
    // 邮箱验证规则
    private static final String EMAIL_REGEX = "^[A-Za-z\\d]+([-_.][A-Za-z\\d]+)*@([A-Za-z\\d]+[-.])+[A-Za-z\\d]{2,4}$";


    /***
     * @methodName TODO 判断是否是一个合法手机号码
     *
     * @param mobilePhone
     * @author wbs
     * @date 2021.6.16 14:48
     * @return boolean
     */
    public static boolean isTelephone(String mobilePhone) {
        return (mobilePhone.matches(TELECOMMUNI_REGEX) ||
                mobilePhone.matches(UNICOM_REGEX) ||
                mobilePhone.matches(MOBILE_REGEX));
    }


    /**
     * @param email
     * @return boolean
     * @methodName TODO 判断是否是一个合法邮箱
     * @author wbs
     * @date 2021.6.16 14:48
     */
    public static boolean isEmail(String email) {
        // 忽略大小写的写法
        Pattern pattern = Pattern.compile(EMAIL_REGEX, Pattern.CASE_INSENSITIVE);
        return pattern.matcher(email).matches();
    }
}
